<!-- 视频设备管理 -->
<template>
  <div>
    <div class="abstatic-height"></div>
    <div id="videoDeviceManager">
      <el-container>
        <el-container>
          <div class="flex-left-pannel" v-if="listAll !== undefined && listAll.length > 0">
            <el-row>
              <div class="xf-tabletop-handles">
                <div class="xf-tabhd-left">
                  <el-button
                    class="filter-item"
                    type="primary"
                    size="mini"
                    v-show="showdownload"
                    @click="addDevice"
                  >添加监控设备
                  </el-button>
                  <el-button type="text" v-show="showdownload" @click="importFn" size="mini">导入表格</el-button>
                  <el-button type="text" @click="download" v-show="showdownload" size="mini">下载表格模版</el-button>
                </div>
                <div class="xf-tabhd-right">设备编号
                  <el-input v-model="listQuery.sensorNo" placeholder="请输入设备编号" class="xf-query-input"
                            size="mini"></el-input>
                  <el-button type="primary" @click="checkList" size="mini">查询</el-button>
                  <el-popover
                    placement="bottom-end"
                    width="700"
                    class="xf-custom-poperone"
                    @show="getSelected"
                    v-model="visible2"
                  >
                    <div class="xf-double-form">
                      <div class="xf-dbform-item">
                        <div class="xf-dbform-item__sleft" style="width:50%;display:inline-block;">
                          <p class="xf-dbform-item__label" style="font-size: 14px;color: #606266;font-weight: 700;">
                            状态</p>
                          <el-select placeholder="请选择状态" v-model="slistQuery.status" style="width:320px;">
                            <el-option label="全部" value=""></el-option>
                            <el-option label="正常" value="2"></el-option>
                            <el-option label="故障" value="0"></el-option>
                            <el-option label="报警" value="1"></el-option>
                            <el-option label="离线" value="4"></el-option>
                            <el-option label="未启用" value="3"></el-option>
                          </el-select>
                        </div>
                        <div class="xf-dbform-item__sright" style="width:49%;display:inline-block;">
                          <p class="xf-dbform-item__label" style="font-size: 14px;color: #606266;font-weight: 700;">
                            设备名</p>
                          <el-input v-model="slistQuery.deviceName" placeholder="请输入设备名"
                                    style="width:320px;"></el-input>
                        </div>
                      </div>
                      <div class="xf-dbform-item">
                        <div class="xf-dbform-item__sleft" style="width:50%;display:inline-block;">
                          <p class="xf-dbform-item__label" style="font-size: 14px;color: #606266;font-weight: 700;">
                            厂商</p>
                          <el-select placeholder="请选择厂商" v-model="slistQuery.manufacturer" style="width:320px;">
                            <el-option
                              :label="item"
                              :value="item"
                              v-for="item in manufeList"
                              :key="item"
                            ></el-option>
                          </el-select>
                        </div>
                        <div class="xf-dbform-item__sright" style="width:49%;display:inline-block;">
                          <p class="xf-dbform-item__label" style="font-size: 14px;color: #606266;font-weight: 700;">
                            系列</p>
                          <el-select placeholder="请选择系列" v-model="slistQuery.equipmentType" style="width:320px;">
                            <el-option
                              :label="item"
                              :value="item"
                              v-for="item in equipmentTypeList"
                              :key="item"
                            ></el-option>
                          </el-select>
                        </div>
                      </div>
                      <div class="xf-dbform-item">
                        <div class="xf-dbform-item__sleft" style="width:50%;display:inline-block;">
                          <p class="xf-dbform-item__label" style="font-size: 14px;color: #606266;font-weight: 700;">
                            型号</p>
                          <el-input v-model="slistQuery.model" placeholder="请输入型号" style="width:320px;"></el-input>
                        </div>
                        <div class="xf-dbform-item__sright" style="width:49%;display:inline-block;">
                          <p class="xf-dbform-item__label" style="font-size: 14px;color: #606266;font-weight: 700;">
                            位置标记</p>
                          <el-select placeholder="请选择状态" v-model="slistQuery.isMark" style="width:320px;">
                            <el-option label="全部" value=""></el-option>
                            <el-option label="已标记" value="1"></el-option>
                            <el-option label="未标记" value="0"></el-option>
                          </el-select>
                        </div>
                      </div>
                    </div>
                    <div style="text-align: left; margin: 0; margin-top:20px;">
                      <el-button size="mini" type="primary" @click="pointerQuery">查询</el-button>
                      <el-button size="mini" type="text" @click="visible2 = false">取消</el-button>
                    </div>
                    <el-button slot="reference" size="mini" type="text">高级查询</el-button>
                  </el-popover>
                </div>
              </div>
            </el-row>
            <el-table
              key="tablekey"
              :data="list"
              ref="multipleTable"
              v-loading.body="listLoading"
              fit
              style="width: 100%"
              @selection-change="handleSelectionChange"
              id="deviceTable"
            >
              <el-table-column type="selection" width="55"></el-table-column>
              <el-table-column label="状态" width="100">
                <template slot-scope="scope">
                  <span style="color:#F5A623;" v-if="scope.row.status==0">故障</span>
                  <span style="color:#FF001F;" v-else-if="scope.row.status==1">报警</span>
                  <span style="color:#389E0D;" v-else-if="scope.row.status==2">正常</span>
                  <span style="color:#B3B8BA;" v-else-if="scope.row.status==3">未启用</span>
                  <span style="color:#B3B8BA;" v-else>离线</span>
                </template>
              </el-table-column>
              <el-table-column label="设备名" class="deviceName">
                <template slot-scope="scope">
                  <span style="overflow: hidden;text-overflow: ellipsis;white-space: nowrap;"
                        :title="scope.row.deviceName">{{ scope.row.deviceName }}</span>
                </template>
              </el-table-column>
              <el-table-column label="设备编号">
                <template slot-scope="scope">
                  <span>{{ scope.row.sensorNo }}</span>
                </template>
              </el-table-column>
              <el-table-column label="通道号">
                <template slot-scope="scope">
                  <span>{{ scope.row.channelNo }}</span>
                </template>
              </el-table-column>
              <el-table-column label="厂商">
                <template slot-scope="scope">
                  <span>{{ scope.row.manufacturer }}</span>
                </template>
              </el-table-column>
              <el-table-column label="系列">
                <template slot-scope="scope">
                  <span>{{ scope.row.equipmentType }}</span>
                </template>
              </el-table-column>
              <el-table-column label="型号">
                <template slot-scope="scope">
                  <span>{{ scope.row.model }}</span>
                </template>
              </el-table-column>
              <el-table-column label="所属设备组">
                <template slot-scope="scope">
                  <span>{{ scope.row.groupName }}</span>
                </template>
              </el-table-column>
              <el-table-column label="位置标记">
                <template slot-scope="scope">
                  <span>{{ scope.row.isMark }}</span>
                </template>
              </el-table-column>
              <el-table-column label="操作" width="130" fixed="right">
                <template slot-scope="scope">
                  <span @click="edit(scope.row)" class="comm-table-btn"><icon-svg icon-class="bianji"
                                                                                  style="fill:#50E3C2"/></span>
                  <span @click="delSensor(scope.row)" class="comm-table-btn"><icon-svg icon-class="shanchu"
                                                                                       style="fill:#50E3C2"/></span>
                </template>
              </el-table-column>
            </el-table>
            <div v-show="!listLoading1" class="sensor-pagination-container">
              <div>
                <el-checkbox
                  v-model="isselall"
                  :indeterminate="isIndeterminate"
                  @change="handleCheckAllChange" v-show="list&&list.length!==0"
                >全选
                </el-checkbox>
                <el-button type="text" style="margin-left: 10px;" @click="delAllSensor" v-show="list&&list.length!==0"
                           :disabled="checklist&&checklist.length==0">全部删除
                </el-button>
              </div>
              <el-pagination
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
                :current-page.sync="listQuery.page"
                :page-sizes="[10,15,30, 50]"
                :page-size="listQuery.limit"
                layout="total, sizes, prev, pager, next, jumper"
                :total="total"
              ></el-pagination>
            </div>
          </div>
          <div class="flex-left-air" v-else>
            <img class="bg-empty" :src="img_zanwu">
            <div class="text">
              当前还没有设备组哦
              <br>
              <span style="text-decoration:underline;color:#50E3C2;" @click="addDevGroup">添加设备组</span>
              之后才能添加监控设备
            </div>
          </div>
        </el-container>
        <el-aside width="250px" class="video-manageside">
          <div class="top clearfix" style="font-size:14px;">
            <div class="xf-tableft-title"><i class="el-icon-caret-right"></i>设备组列表</div>
            <p class="viewall-video" @click="viewAll" :class="{active:isActive}">全部设备组</p>
            <span @click="addDevGroup" class="addvideo"><i class="el-icon-plus"></i>添加</span>
          </div>
          <div class="content" style="font-size:14px;" v-if="listAll != undefined && listAll.length > 0">
            <div class="device-list" v-for="(item,index) in listAll" :key="index">
            <span
              style="flex:9;"
              :class="{'active':index===curactive}"
              @click="viewPerdev(item.id,item.deviceGroupName,index)"
              :title="item.deviceGroupName"
            >{{ item.deviceGroupName }}</span>
              <div class="manage" style="flex:1.5;" @click="editorDevice(item.id)">
                <icon-svg
                  icon-class="bianji"
                  style="fill:#50E3C2;cursor:pointer;margin-right:5px;"
                />
              </div>
              <div class="manage" style="flex:1.5;" @click.stop="delDevice(item.id)">
                <icon-svg
                  icon-class="shanchu"
                  style="fill:#50E3C2;cursor:pointer;"
                />
              </div>
            </div>
          </div>
          <div class="content-one" v-else>
            <div class="text">
              当前还没有设备组哦
              <br>开始
              <span style="text-decoration:underline;color:#5EA6FF;" @click="addDevGroup">添加设备组</span>
            </div>
          </div>
        </el-aside>
      </el-container>
      <slider-panel :Show.sync="addsensorGroupShow" custom-class="out-side-frame">
        <div class="form-content-frame">
          <el-form :model="addSensorGroup" :rules="groupRules" ref="addSensorGroup" @submit.native.prevent>
            <el-form-item label="设备组" prop="sensorGroupName">
              <el-input v-model.trim="addSensorGroup.sensorGroupName" placeholder="请输入设备组名称"></el-input>
            </el-form-item>
            <el-form-item>
              <div class="second-line">
                <span style="font-size: 14px;color:#fff;font-weight:700;">平面图</span>
              </div>
            </el-form-item>
            <!--          <el-form-item>-->
            <!--            <div class="uploadBox" v-if="!addSensorGroup.dialogImageUrl" @click="uploadPlanimg" style="font-size:12px;">-->
            <!--              <i class="el-icon-circle-close-outline" v-if="addSensorGroup.dialogImageUrl" @click="delImage">-->

            <!--              </i>-->
            <!--              <i class="el-icon-circle-plus" ></i>-->
            <!--              <br>-->
            <!--              <div class="line-one" style="display:inline-block;">-->
            <!--                <span>点击添加平面图</span>-->
            <!--                <br>-->
            <!--                <span>支持.jpg/png格式</span>-->
            <!--                <br>-->
            <!--                <span>不超过10M</span>-->
            <!--              </div>-->
            <!--            </div>-->
            <!--            <div class="conimgBox" style="width:100%;position:relative;" v-else>-->
            <!--                <img class="uploadBox1" :src="addSensorGroup.dialogImageUrl" alt="" >-->
            <!--                <i class="el-icon-circle-close-outline" style="position:absolute;top: 7%;color: #50E3C2" @click="closeImg"></i>-->
            <!--            </div>-->
            <!--          </el-form-item>-->
            <el-form-item label="大文件上传">
              <uploader :options="options" class="uploader-example"
                        @file-added="onFileAdded">
                <uploader-unsupport></uploader-unsupport>
                <uploader-drop>
                  <p>Drop files here to upload or</p>
                  <uploader-btn>select files</uploader-btn>
<!--                  <uploader-btn :attrs="attrs">select images</uploader-btn>-->
<!--                  <uploader-btn :directory="true">select folder</uploader-btn>-->
                </uploader-drop>
                <uploader-list></uploader-list>
              </uploader>
            </el-form-item>


            <el-form-item style="margin-top:20px;">
              <el-button v-if="dialogStatusdev==='create'" size="mini" type="primary"
                         @click="addConfirm('addSensorGroup')" native-type="submit">确定
              </el-button>
              <el-button v-else size="mini" type="primary" @click="updateConfirm('addSensorGroup')"
                         native-type="submit">确定
              </el-button>
              <el-button size="mini" type="text" @click="canceladd('addSensorGroup')">取消</el-button>
            </el-form-item>
            <el-upload
              action
              ref="upload"
              :http-request="uploadSectionFile"
              accept="image/*"
              :before-upload="beforeupload"
              :on-remove="handleRemove"
              class="uploadimgvideo"
            ></el-upload>
            <el-dialog :visible.sync="updialogVisible">
              <img width="100%" :src="addSensorGroup.dialogImageUrl" alt="">
            </el-dialog>
          </el-form>
        </div>
      </slider-panel>
      <slider-panel :Show.sync="isaddsensor" custom-class="out-side-frame">
        <div class="form-content-frame">
          <el-form
            :model="sensorForm"
            ref="addsensorform"
            :rules="sensorrules"
            label-width="100px"
            label-position="top"
            @submit.native.prevent
          >
            <el-form-item>
              <div class="sGroup" style="font-weight:700;color: #50E3C2;">
                <span>所属设备组：{{ deviceGroupName }}</span>
              </div>
            </el-form-item>
            <el-form-item label="设备编号" prop="sensorNo">
              <el-input :clearable='true' v-model.trim="sensorForm.sensorNo" placeholder="请输入设备编号"
                        :disabled="dialogStatus =='update' ? true:false"></el-input>
            </el-form-item>
            <el-form-item label="验证码" prop="deviceValidateCode">
              <el-input :clearable='true' v-model.trim="sensorForm.deviceValidateCode" placeholder="请输入验证码"
                        :disabled="dialogStatus =='update' ? true:false"></el-input>
            </el-form-item>
            <el-form-item label="通道号" prop="channelNum">
              <el-input :clearable='true' v-model.trim="sensorForm.channelNum" placeholder="请输入通道号"
                        :disabled="dialogStatus =='update' ? true:false"></el-input>
            </el-form-item>
            <el-form-item label="厂商/系列/型号" prop="manufacturerName">
              <el-cascader
                :options="entityOptions"
                filterable
                :clearable='true'
                v-model.trim="sensorForm.manufacturerName"
                style="width:100%"
              ></el-cascader>
            </el-form-item>
            <el-form-item label="标记位置" prop="positionSign">
              <el-input :clearable='true'
                        v-model.trim="sensorForm.positionSign=='' || sensorForm.positionSign== undefined || sensorForm.positionSign== null ?'未标记':'已标记'">
                <el-button
                  slot="append"
                  icon="el-icon-location"
                  @click="markPlace"
                >标记地点
                </el-button>
              </el-input>
            </el-form-item>
            <el-form-item label="设备名" prop="deviceName">
              <el-input :clearable='true' v-model.trim="sensorForm.deviceName" placeholder="请输入设备名"></el-input>
            </el-form-item>
            <el-button :disabled="conDisabled" v-if="dialogStatus=='create'" type="primary"
                       @click="create('addsensorform')" size="mini" native-type="submit">确定
            </el-button>
            <el-button v-else type="primary" @click="updateSensor('addsensorform')" size="mini" native-type="submit">确
              定
            </el-button>
            <el-button @click="cancel('addsensorform')" type="text" size="mini">取 消</el-button>
          </el-form>
        </div>
      </slider-panel>
      <el-dialog
        title="导入文件"
        :visible.sync="dialogImportVisible"
        :close-on-click-modal="false"
        :show-close="false"
        width="400px"
        top="40vh"
        custom-class="upload-cum"
      >
        <p class="uploadtitle">导入文件类型：xlsx 或 xls，大小不超过10M</p>
        <el-upload
          class="upload-wrap"
          :class="{filedisabled:uploadDisabled}"
          ref="upload"
          drag
          :headers="token"
          :action="uploadUrl"
          :data="uploadparams"
          :onSuccess="uploadSuccess"
          :on-progress="uploadOnProgress"
          :on-error="uploaderr"
          :beforeUpload="beforeUpload"
          :limit="1"
        >
          <el-button slot="trigger" class="uploadarea">+ 请选择或拖拽上传文件</el-button>
        </el-upload>
        <div slot="footer" class="dialog-footer">
          <el-button @click="cancelUpload" type="primary" v-show="!uploadLoading">知道了</el-button>
        </div>
      </el-dialog>
      <el-dialog title="标记位置" :visible.sync="isfloorimg" :show-close='false' custom-class="xf-jc-dialog"
                 width="360px" height="160px">
        <div class="xf-jc-deletect">
          <p>{{ isfloorimgtext }}</p>
        </div>
        <div slot="footer" class="dialog-footer">
          <!-- <el-button type="primary" round size="medium" @click="goUpload">去上传</el-button> -->
          <el-button type="primary" size="medium" @click="isfloorimg=false">确定</el-button>
        </div>
      </el-dialog>
      <el-dialog title="删除监控设备" :visible.sync="isdelsensor" :show-close='false' custom-class="xf-jc-dialog"
                 width="360px" height="160px">
        <div class="xf-jc-deletect">
          <p>{{ delsensortext }}</p>
        </div>
        <div slot="footer" class="dialog-footer">
          <el-button type="danger" size="medium" @click="handleDelete">删除</el-button>
          <el-button type="text" size="medium" @click="isdelsensor=false">取消</el-button>
        </div>
      </el-dialog>
      <el-dialog title="删除设备组" :visible.sync="isdelsensorGroup" :show-close='false' custom-class="xf-jc-dialog"
                 width="360px" height="160px">
        <div class="xf-jc-deletect">
          <p>{{ delsensorgrouptext }}</p>
        </div>
        <div slot="footer" class="dialog-footer">
          <el-button type="danger" size="medium" @click="handleGroupDelete">删除</el-button>
          <el-button type="text" size="medium" @click="isdelsensorGroup=false">取消</el-button>
        </div>
      </el-dialog>
      <markPlace :Show.sync="ismarkplace" :getimgpath.sync="imgpath" :sensorinfo="sensorinfo"
                 :positionSign.sync="sensorForm.positionSign" @sendMarkInfo="sendMarkInfo"></markPlace>
    </div>
  </div>
</template>
<script>
import SparkMD5 from 'spark-md5';
import {
  getDeviceTree,
  page,
  advanceSelected,
  addSelected,
  addSensor,
  deleteDevices,
  checkDevice,
  updateObj,
  addVideoGroupcon,
  delVideoGroup,
  editVideoGroup,
  updateVideoGroup
} from "@/api/device/deviceVideoExt/index";
import {getToken} from "@/utils/auth";
import markPlace from '@/views/device/deviceManger/components/markPlace';
import img_zanwu from "@/assets/device-images/zanwu.png";
import sliderPanel from '@/components/SliderPanel'

export default {
  name: "devicemanager",
  components: {markPlace, sliderPanel},
  data() {
    var sensorNo = (rule, value, callback) => {
      if (!value) {
        return callback(new Error('请输入设备编号'))
      }
      setTimeout(() => {
        if (value.length < 1 || value.length > 100) {
          callback(new Error('最多允许输入100个字符'))
        } else {
          callback()
        }
      }, 1000)
    };
    var deviceValidateCode = (rule, value, callback) => {
      if (!value) {
        return callback(new Error('验证码不能为空'))
      } else {

        callback();
      }
    };
    var channelNum = (rule, value, callback) => {
      var reg = new RegExp('^([1-9]|[1-5][0-9]|[6][0-4])$');
      if (!value) {
        return callback(new Error('通道号不能为空'))
      }
      setTimeout(() => {
        if (!reg.test(value)) {
          callback(new Error('通道号必须为1-64的数字值'))
        } else {
          callback()
        }
      }, 1000)
    };
    var deviceName = (rule, value, callback) => {
      if (!value) {
        return callback(new Error('请输入设备名'))
      }
      setTimeout(() => {
        if (value.length < 1 || value.length > 50) {
          callback(new Error('最多允许输入50个字符'))
        } else {
          callback()
        }
      }, 1000)
    };
    var manufacturerName = (rule, value, callback) => {
      if (!value) {
        return callback(new Error('请选择 厂商 / 系列 / 型号'))
      } else {
        callback();
      }
    }
    return {
      attrs: {
        accept: 'image/*'
      },
      options: {
        target:'http://localhost:2222/'+'file/postFileUpload', // 目标上传 URL
        chunkSize: '2048000',  //分块大小
        fileParameterName: 'file', //上传文件时文件的参数名，默认file
        maxChunkRetries: 3,  //最大自动失败重试上传次数
        testChunks: false,     //是否开启服务器分片校验
      },
      isActive: true,
      curactive: -1,
      conDisabled: false,
      updateGroupId: "",
      listLoading1: false,
      groupId: "",
      isfloorimgtext: "",
      isfloorimg: false,
      delsensorgrouptext: "",
      isdelsensorGroup: false,
      updialogVisible: false,
      addSensorGroup: {
        dialogImageUrl: '',
        sensorGroupName: "",
      },

      dialogVisible: false,
      imgpath: "",
      delsensortext: "",
      isdelsensor: false,
      deviceGroupName: "",
      uploadUrl: "api/device/deviceVideoExt/importDevices", //上传表格位置
      uploadDisabled: false,
      dialogImportVisible: false,
      token: {'Authorization': getToken()},
      img_zanwu: img_zanwu,

      showdownload: false,
      visible2: false,
      deviceList: [],
      slistQuery: {
        status: "", //状态
        manufacturer: "", //厂商
        equipmentType: "", //系列
        model: "", //型号
        deviceName: "", //设备名
        isMark: "" //位置标记
      },
      listQuery: {
        page: 1,
        limit: 15,
        sensorNo: undefined,
        groupId: ""
      },
      uploadparams: undefined,
      entityOptions: [],
      seriesOptions: [],
      typesOptions: [],
      listLoading: false,
      isselall: false,
      isIndeterminate: false,
      addinnerVisible: false,
      sensorForm: {
        sensorNo: "",
        deviceValidateCode: "",
        channelNum: "",
        manufacturerName: [],
        deviceName: "",
        positionSign: ""
      },
      manufeList: [],
      equipmentTypeList: [],
      planSetup: "0",
      isaddsensor: false,
      addsensorGroupShow: false,
      ismarkplace: false,
      sensorinfo: {
        num: "", //编号
        name: ""
      },
      list: [],
      total: null,
      listAll: ["假山", "鱼缸"],
      dialogStatus: "",
      textMap: {
        update: "编辑传感器",
        create: "添加传感器"
      },
      textMapdev: {
        update: "编辑设备组",
        create: "添加设备组"
      },
      dialogStatusdev: "",
      maptitle: "",
      curChannelId: "",
      sensorrules: {
        sensorNo: [
          {validator: sensorNo, trigger: 'blur', required: true}
        ],
        deviceValidateCode: [
          {validator: deviceValidateCode, trigger: 'blur', required: true}
        ],
        channelNum: [
          {validator: channelNum, trigger: 'blur', required: true}
        ],
        deviceName: [
          {validator: deviceName, trigger: 'blur', required: true}
        ],
        manufacturerName: [
          {validator: manufacturerName, trigger: 'blur', required: true}
        ]
      },
      uploadLoading: false,
      checklist: [],
      delsensorid: [],
      checkId: "",
      uploadurl: "/api/device/deviceUploadInformation/save",
      delGroupId: "",
      groupRules: {
        sensorGroupName: [
          {required: true, message: '请输入设备组名称', trigger: 'blur'},
          {min: 3, max: 50, message: '长度在 3 到 50 个字符', trigger: 'blur'}
        ]
      }
    };
  },
  created() {
  },
  computed: {},
  methods: {
    // **methods方法，MD5对文件签名 **
    onFileAdded(file) {
      const fileReader = new FileReader()
      fileReader.readAsBinaryString(file);
      fileReader.onload = e => {
        const md5 = SparkMD5.hashBinary(e.target.result);
        console.log(md5);
        file.uniqueIdentifier = md5;
      }
    }
    ,
    handleRemove(file, fileList) {
      this.addSensorGroup.dialogImageUrl = "";
    }
    ,
    closeImg() {
      this.addSensorGroup.dialogImageUrl = "";
    }
    ,
    goUpload() {
      //  this.$router.push("/adminSys/buildManager")
      // this.addsensorGroupShow = true;
    }
    ,
    sendMarkInfo(pos) {
      this.sensorForm.positionSign = pos;
      this.ismarkplace = false;
    }
    ,
    download() {
      window.open("http://tds-download.turing.ac.cn/videoDeviceImport2.xls")
    }
    ,
    handleSelectionChange(val) {
      this.checklist = [...val];
      let length = this.total > this.list.length ? this.list.length : this.total;
      if (val.length == length) {
        this.isselall = true;
        this.isIndeterminate = false
      } else {
        this.isselall = false;
        this.isIndeterminate = true;
      }
      if (val.length === 0) {
        this.isIndeterminate = false;
      }
    }
    ,
// 全部删除
    delAllSensor() {
      this.delsensorid = [];
      this.delsensortext = `删除此传感器将导致该点位的监测数据被清空，确定删除吗？`;
      this.checklist.forEach((item, index) => {
        this.delsensorid.push(item.id);
      });
      this.isdelsensor = true;
      this.isselall = true;
    }
    ,
// 添加设备组确定
    addConfirm(formName) {
      const set = this.$refs;
      set[formName].validate(valid => {
        if (valid) {
          let canshu = {
            deviceGroupName: this.addSensorGroup.sensorGroupName,
            deviceGroupImage: this.addSensorGroup.dialogImageUrl
          }
          addVideoGroupcon(canshu).then(res => {
            this.addSensorGroup.sensorGroupName = "";
            this.addSensorGroup.dialogImageUrl = "";
            this.initLoad();
            if (res.status == 200) {
              this.$notify({
                title: "成功",
                message: "创建成功",
                type: "success",
                duration: 2000
              });
            } else {
              this.$notify({
                title: "失败",
                message: res.message,
                type: "warning",
                duration: 2000
              });
            }
            this.addsensorGroupShow = false;
            this.addsensorGroup = {};
            this.$refs[formName].resetFields();
          });
        } else {
          return false;
        }
      })
    }
    ,
    updateConfirm(formName) {
      const set = this.$refs;
      set[formName].validate(valid => {
        if (valid) {
          updateVideoGroup(this.updateGroupId, {
            id: this.updateGroupId, deviceGroupName: this.addSensorGroup.sensorGroupName,
            deviceGroupImage: this.addSensorGroup.dialogImageUrl
          }).then(res => {

            if (res.status == 200) {
              this.$notify({
                title: "成功",
                message: "创建成功",
                type: "success",
                duration: 2000
              });
            } else {
              this.$notify({
                title: "失败",
                message: res.message,
                type: "error",
                duration: 2000
              });
            }
            this.addSensorGroup.sensorGroupName = "";
            this.addSensorGroup.dialogImageUrl = "";
            this.initLoad();
            this.addsensorGroupShow = false;
            this.$refs[formName].resetFields();
          })
        } else {
          return false;
        }
      })
    }
    ,
    canceladd(formName) {
      this.addSensorGroup.sensorGroupName = "";
      this.addSensorGroup.dialogImageUrl = "";
      this.addsensorGroupShow = false;
      this.$refs[formName].resetFields();
    }
    ,

// 查看设备
    edit(row) {
      this.dialogStatus = "update";
      this.isaddsensor = true;
      this.checkId = row.id;
      this.deviceGroupName = row.groupName;
      addSelected({channelId: this.curChannelId}).then(res => {
        this.entityOptions = res.data.options;
      });
      checkDevice({id: this.checkId}).then(res => {
        this.sensorForm.sensorNo = res.data.sensorNo;
        this.sensorForm.manufacturerName = res.data.deviceTypes;
        this.sensorForm.deviceName = res.data.deviceName;
        this.sensorForm.channelNum = res.data.channelNo;
        this.sensorForm.positionSign = res.data.positionSign;
        this.sensorForm.deviceValidateCode = res.data.validateCode;
        this.sensorForm.id = res.data.id;
        this.groupId = res.data.groupId;
      }).then(() => {
        editVideoGroup(this.groupId).then(res => {
          if (res.data.length != 0) {
            this.imgpath = res.data.deviceGroupImage.split('?')[0];
          } else {
            this.imgpath = '';
          }
        })
      })
    }
    ,
// 编辑设备
    updateSensor(formName) {
      const set = this.$refs;
      let canshu = this.$qs.stringify({
        id: this.sensorForm.id,
        manufacturerName: this.sensorForm.manufacturerName[0],
        equipmentType: this.sensorForm.manufacturerName[1],
        model: this.sensorForm.manufacturerName[2],
        deviceName: this.sensorForm.deviceName,
        positionSign: this.sensorForm.positionSign
      });
      set[formName].validate(valid => {
        if (valid) {
          updateObj(canshu).then((res) => {
            this.getList();
            if (res.status == 200) {
              this.$notify({
                title: "成功",
                message: "更新成功",
                type: "success",
                duration: 2000
              });
            } else {
              this.$notify({
                title: "成功",
                message: "更新成功",
                type: "success",
                duration: 2000
              });
            }
            set[formName].resetFields();
            this.handlerest();
            this.isaddsensor = false;
          });
        } else {
          return false;
        }
      });
    }
    ,
// 删除设备
    delSensor(row) {
      this.delsensortext = "确定要删除该监控设备吗？";
      this.delsensorid = [];
      this.delsensorid.push(row.id);
      this.isdelsensor = true;
    }
    ,
    handleDelete() {
      deleteDevices({ids: this.delsensorid.join(',')}).then(res => {
        if (res.status == 200) {
          this.$notify({
            title: "成功",
            message: "删除成功",
            type: "success",
            duration: 2000
          });
          this.getList();
          this.isdelsensor = false;
          this.listQuery.page = 1;
          this.isselall = false;
          this.isIndeterminate = false;
          // this.listLoading1=true;
        } else {
          this.$notify({
            title: "成功",
            message: "更新成功",
            type: "success",
            duration: 2000
          });
          this.getList();
          this.isdelsensor = false;
          this.listQuery.page = 1;
          this.isselall = false;
          this.isIndeterminate = false;
          // this.listLoading1=true;
        }

      })
    }
    ,
// 查看全部按钮
    viewAll() {
      this.isActive = true;
      this.curactive = -1;
      this.showdownload = false;
      this.listQuery.groupId = "";
      this.getList();
    }
    ,
// 获取高级查询里面的下拉框
    getSelected() {
      this.slistQuery.status = '';
      this.slistQuery.deviceName = '';
      this.slistQuery.manufacturer = '';
      this.slistQuery.equipmentType = '';
      this.slistQuery.model = '';
      this.slistQuery.isMark = '';
      advanceSelected({channelId: this.curChannelId}).then(res => {
        this.manufeList = res.data.manufacturer;
        this.equipmentTypeList = res.data.equipmentType;
      });
    }
    ,
// 清空高级查询的条件
    resetgj() {
      this.slistQuery.status = '';
      this.slistQuery.deviceName = '';
      this.slistQuery.manufacturer = '';
      this.slistQuery.equipmentType = '';
      this.slistQuery.model = '';
      this.slistQuery.isMark = '';
    }
    ,
// 高级查询确定
    pointerQuery() {
      this.visible2 = false;
      this.listLoading = true;
      this.listQuery.page = 1;
      let canshu = Object.assign({}, JSON.parse(JSON.stringify(this.listQuery)), JSON.parse(JSON.stringify(this.slistQuery)));
      page(canshu).then(res => {
        this.list = res.data.rows;
        this.total = res.data.total;
        this.listLoading = false;
      });

    }
    ,
// 查询
    checkList() {
      this.resetgj();
      this.getList();
    }
    ,
// 查询按钮
    getList() {
      this.listLoading = true;
      let canshu = Object.assign(
        {},
        JSON.parse(JSON.stringify(this.listQuery))
      );

      page(canshu)
        .then(response => {
          this.list = response.data.rows;

          this.total = response.data.total;
          this.listLoading = false;
        })
        .catch(() => {
          this.listLoading = false;
        });
    }
    ,
    fetchData() {
      this.resetgj();
      this.curChannelId = this.$route.params.id;
      this.initLoad();
    }
    ,
    initLoad() {
      getDeviceTree().then(res => {
        this.listAll = res;
      });
      this.getList();
    }
    ,
// 导入表格
    importFn() {
      this.uploadparams = {deviceGroupId: this.listQuery.groupId, channelId: this.curChannelId};
      this.dialogImportVisible = true;
    }
    ,
// 标记位置
    markPlace() {
      if (this.imgpath == "" || this.imgpath == undefined) {
        this.isfloorimgtext = `请上传平面图！`;
        this.isfloorimg = true;
      } else {
        this.sensorinfo.num = this.sensorForm.sensorNo;
        this.sensorinfo.name = this.sensorForm.manufacturerName;

        this.ismarkplace = true;
      }
    }
    ,
// 添加传感器
    addDevice() {
      this.dialogStatus = "create";
      this.isaddsensor = true;
      this.handlerest();
      editVideoGroup(this.listQuery.groupId).then(res => {
        this.imgpath = res.data.deviceGroupImage.split('?')[0];
      }).then(() => {
        addSelected({channelId: this.curChannelId}).then(res => {
          this.entityOptions = res.data.options;
        });
      })
    }
    ,
// 添加传感器确定按钮
    create(formName) {
      const set = this.$refs;
      let canshu = this.$qs.stringify({
        sensorNo: this.sensorForm.sensorNo,
        deviceValidateCode: this.sensorForm.deviceValidateCode,
        channelNo: this.sensorForm.channelNum,
        groupId: this.listQuery.groupId,
        manufacturerName: this.sensorForm.manufacturerName[0],
        equipmentType: this.sensorForm.manufacturerName[1],
        model: this.sensorForm.manufacturerName[2],
        deviceName: this.sensorForm.deviceName,
        positionSign: this.sensorForm.positionSign
      });
      set[formName].validate(valid => {
        if (valid) {
          addSensor(canshu).then(res => {
            set[formName].resetFields();
            this.handlerest();
            this.getList();
            if (res.status == 200) {
              this.$notify({
                title: "成功",
                message: "创建成功",
                type: "success",
                duration: 2000
              });
              //  this.conDisabled = false;
            } else {
              this.$notify({
                title: "失败",
                message: res.message,
                type: "warning",
                duration: 2000
              });
            }
            this.sensorForm = {};

            this.isaddsensor = false;
            //  清空全选
            this.isselall = false;
            this.isIndeterminate = false;
            this.getList();
          }).catch(function (error) {
            console.log(error);
          });
        } else {
          return false;
        }
      });
    }
    ,
    handlerest() {
      this.sensorForm.manufacturerName = [];
      this.sensorForm.positionSign = "";
      this.sensorForm.channelNum = "";
      this.sensorForm.deviceName = "";
      this.sensorForm.deviceValidateCode = "";
      this.sensorForm.sensorNo = "";
    }
    ,
    cancel(formName) {
      const set = this.$refs;
      set[formName].resetFields();
      this.handlerest();
      this.isaddsensor = false;
    }
    ,
    beforeupload(file) {
      let testmsg = file.name.substring(file.name.lastIndexOf(".") + 1);
      const extension = ["jpg", "png"].includes(testmsg);
      const is1M = file.size / 1024 / 1024 < 10;
      if (!extension) {
        this.$notify({
          message: "请上传正确的文档格式!",
          type: "error",
          duration: 2000
        });
      }
      if (!is1M) {
        this.$notify({
          message: "上传文件大小不能超过 10MB!",
          type: "error",
          duration: 2000
        });
      }
      this.isupload = true;
      return extension && is1M;
    }
    ,
    uploadSectionFile: function (param) {
      this.uploadurl = "/api/device/deviceUploadInformation/save";
      let file = param.file;
      let self = this,
        curimgurl;
      let token = getToken();
      let FileController = this.uploadurl + "?fileName=" + file.name;
      let form = new FormData();
      form.append("file", file);
      let xhr = new XMLHttpRequest();
      xhr.open("post", FileController, true);
      xhr.setRequestHeader("Authorization", token);
      xhr.onload = function (res) {
        if (res.currentTarget.status == 200) {
          // debugger;
          // self.handleAvatarSuccess(res.currentTarget);
          let data = JSON.parse(res.currentTarget.response);
          self.addSensorGroup.dialogImageUrl = data.data.url;
          self.isuploading = false;
          self.$notify({
            title: "成功",
            message: "上传成功!",
            type: "success",
            duration: 2000
          });
        } else {
          self.$notify({
            title: "失败",
            message: res.message,
            type: "warning",
            duration: 2000
          });
        }
      };
      xhr.upload.onloadstart = function () {
        //上传开始执行方法
        self.isuploading = true;
      };
      xhr.send(form);
    }
    ,
    addDevGroup() {
      this.dialogStatusdev = "create";
      this.addsensorGroupShow = true;
      this.addSensorGroup.sensorGroupName = '';
      this.addSensorGroup.dialogImageUrl = '';
    }
    ,
    handleCheckAllChange() {
      this.$refs.multipleTable.toggleAllSelection();
    }
    ,
    handleCurrentChange(val) {
      this.listQuery.page = val;
      this.getList();
    }
    ,
    handleSizeChange(val) {
      this.listQuery.limit = val;
      this.getList();
    }
    ,
    editorDevice(val) {
      this.dialogStatusdev = "update";
      this.addsensorGroupShow = true;
      this.updateGroupId = val;
      editVideoGroup(val).then(res => {
        // this.addSensorGroup={};
        this.addSensorGroup.sensorGroupName = res.data.deviceGroupName;
        this.addSensorGroup.dialogImageUrl = res.data.deviceGroupImage.split('?')[0];
        ;
      })
    }
    ,
    delDevice(val) {
      this.isdelsensorGroup = true;
      this.delsensorgrouptext = '设备组中绑定的监控设备将会同步删除，确定删除吗？'
      this.delGroupId = val;
      this.initLoad();
    }
    ,
    handleGroupDelete() {
      delVideoGroup(this.delGroupId).then(res => {
        this.isdelsensorGroup = false;
        if (res.status == 200) {
          this.$notify({
            title: "成功",
            message: "删除成功",
            type: "success",
            duration: 2000
          });
        } else {
          this.$notify({
            title: "失败",
            message: res.message,
            type: "warning",
            duration: 2000
          });
        }
        this.isselall = false;
        this.initLoad();
      })
    }
    ,
// 关闭弹框
    cancelAddSensor() {

    }
    ,
    uploadPlanimg() {
      if (self.isuploading) {
        this.$notify({
          message: "请等待文件上传完毕!",
          type: "warning",
          duration: 2000
        });
      } else {
        document.querySelector(".el-upload__input").click();
      }
    }
    ,
    viewPerdev(ids, deviceGroupName, index) {
      this.curactive = index;
      this.isActive = false;
      this.restQuery();
      this.showdownload = true;
      this.listQuery.groupId = ids;
      this.deviceGroupName = deviceGroupName;
      let canshu = Object.assign({}, JSON.parse(JSON.stringify(this.listQuery)));
      page(canshu)
        .then(response => {
          this.list = response.data.rows;
          this.total = response.data.total;
          this.listLoading = false;
        })
        .catch(() => {
          this.listLoading = false;
        });
    }
    ,
    restQuery() {
      this.isselall = false;
      this.isIndeterminate = false;
      this.slistQuery.status = "-1";
      this.slistQuery.manufacturer = "全部";
      this.slistQuery.equipmentType = "全部";
      this.slistQuery.isMark = "-1";

      this.slistQuery.model = "";
      this.deviceName = "";
    }
    ,
    handleSelectMap() {
      this.dialogMapselected = true;
    }
    ,
    getMark(val) {
      this.sensorForm.positionSign = val;
      this.addinnerVisible = false;
    }
    ,
// 导入表格
    beforeUpload(file) {
      var testmsg = file.name.substring(file.name.lastIndexOf(".") + 1);
      const extension = testmsg === "xls";
      const extension2 = testmsg === "xlsx";
      const isLt2M = file.size / 1024 / 1024 < 10;
      if (!extension && !extension2) {
        this.$message({
          message: "上传文件只能是 xls、xlsx格式!",
          type: "warning"
        });
      }
      if (!isLt2M) {
        this.$message({
          message: "上传文件大小不能超过 10MB!",
          type: "warning"
        });
      }
      return (extension || extension2) && isLt2M;
    }
    ,
// 上传过程中的加载
    uploadOnProgress(e) {
      let progress = Math.floor(e.percent);
      // 如果上传成功
      if (progress == "100") {
        this.uploadLoading = true;
      }
    }
    ,
    uploadSuccess(response, file) {
      if (response.status == "200") {
        this.cancelUpload();
        this.$message({
          message: "导入成功！",
          type: "success"
        });
        // 刷新列表
        this.getList();
        //  清空全选
        this.isselall = false;
        this.isIndeterminate = false;
      } else if (response.status === "307") {
        // 文件格式错误
        this.cancelUpload();
        this.$message.error(response.message);
      } else {
        this.cancelUpload();
        this.$message.error(response.message);
        this.uploadLoading = false;
      }
    }
    ,
    uploaderr(err) {
      this.cancelUpload();
      this.$message.error(JSON.parse(err.message).message);
      this.uploadLoading = false;
    }
    ,
    cancelUpload() {
      this.$refs.upload.clearFiles();
      this.dialogImportVisible = false;
      this.uploadLoading = false;
    }
  },
  mounted() {
    this.fetchData();
  }
  ,
  watch: {
    $route: "fetchData"
  }
}
;
</script>
<style rel="stylesheet/scss" lang="scss">
#videoDeviceManager {
  padding-left: 20px;

  .el-tree-node__children {
    i {
      &.itemstatus {
        vertical-align: middle;
        margin-right: 5px;
        width: 6px;
        height: 6px;
        display: inline-block;
        border-radius: 100%;
      }

      &.status0 {
        background: #ffab22;
      }

      &.status1 {
        background: #ff0000;
      }

      &.status2 {
        background: #67a91b;
      }
    }
  }

  .flex-left-air {
    width: 100%;
    padding-right: 30px;
    padding-top: 20px;

    .bg-empty {
      width: 100%;
      height: 426px;
    }

    .text {
      padding-top: 60px;
      text-align: center;
    }
  }

  // 随机色背景剪切
  .dot-circl {
    background: currentColor;
    clip-path: circle(11%);
  }

  .video-manageside {
    padding: 10px 30px 20px 10px;
    margin-right: 10px;
    background: linear-gradient(-140deg, transparent 2em, #0A1722 0);
    position: relative;
    min-height: 86vh;
    box-sizing: border-box;
    color: rgba(255, 255, 255, .7);

    .active {
      color: #50E3C2;
    }

    &:before {
      content: '';
      position: absolute;
      top: 0;
      bottom: 0;
      left: 0;
      right: 0;
      border: 2px solid #50E3C2;
      clip-path: polygon(0 0, 30px 0, 30px 100%, 0 100%);
    }

    .viewall-video {
      cursor: pointer;
      padding: 10px;

      &.active {
        background: rgba(0, 0, 0, .3);
      }
    }

    .addvideo {
      cursor: pointer;
      color: #50E3C2;
      position: absolute;
      top: 20px;
      right: 46px;
    }

    .content {
      .device-list {
        height: 36px;
        line-height: 36px;
        display: flex;
        flex-direction: row;
        align-items: center;
        padding-left: 10px;
        cursor: pointer;

        span {
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
        }
      }

      .text {
        display: inline-block;
        font-size: 14px;
      }
    }

    .content-one {
      text-align: center;
      display: inline-block;
      width: 100%;
      padding-top: 50px;
      font-size: 14px;

      span {
        cursor: pointer;
      }
    }

    .el-scrollbar__wrap {
      overflow-x: hidden;
    }

    .el-tree-node__label {
      font-size: 14px;
      text-overflow: ellipsis;
      overflow: hidden;
    }
  }

  .xf-query-input,
  .xf-query-select {
    width: 200px;
    margin: 0 10px;
  }

  .addsensordialog > div,
  .addsensorGroup > div {
    width: 500px;
    margin: 0 auto;
  }

  .addsensordialog .el-dialog__title {
    font-size: 32px;
  }

  .addsensordialog {
    .el-dialog__header {
      margin-top: 20px;
    }

    .custom-dialog-btn {
      position: absolute;
      font-size: 30px;
      left: 40px;
      top: 20px;
      color: #fff;

      &:hover {
        cursor: pointer;
      }
    }

    .dialog-footer {
      text-align: left;
    }

    //   带下拉选择的输入
    .tmselect .el-input {
      width: 80px;
    }

    .input-with-select .el-input-group__append {
      background-color: #fff;
    }
  }

  // 精准查询
  .xf-double-form {
    .xf-dbform-item {
      display: flex;
      justify-content: space-between;

      .xf-dbform-item__sleft {
        .el-input {
          width: 320px;
        }
      }

      .xf-dbform-item__sright {
        .el-input {
          width: 320px;
        }
      }
    }
  }

  .upload-cum {
    .el-dialog__body {
      padding-top: 0;
      min-height: 40px;
      padding-bottom: 10px;
    }

    .dialog-footer {
      text-align: left;
    }

    .el-button.is-disabled {
      background-color: #d9d9d9;
      color: #fff;
      border-color: #d9d9d9;
    }

    .upload-wrap {
      width: 100%;
      margin-top: 20px;

      .el-upload {
        width: 100%;
      }
    }

    .el-upload-list__item {
      padding: 8px 0;
      background: #f1f1f1;

      .el-icon-close {
        top: 14px;
      }

      .el-icon-upload-success {
        vertical-align: bottom;
      }
    }

    .el-upload-dragger {
      height: 40px;
    }

    .filedisabled .el-upload {
      display: none;
    }

    .el-button--default {
      border-color: #dcdfe6;
    }

    .uploadarea {
      width: 100%;
      line-height: 16px;
      background-color: #f1f1f1;
      border-radius: 2px;
      font-size: 14px;
      color: #666;
    }

    .el-upload-list__item .el-progress {
      top: 30px;
    }
  }

  .sensor-pagination-container {
    display: flex;
    justify-content: space-between;
    padding: 10px 10px;
  }

  .build-custom-tree-node {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 14px;
    padding-right: 8px;
  }

}

.uploadBox1 {
  width: 120px;
  height: 120px;
  display: inline-block;
  padding: 10px;
  text-align: center;
  margin-top: 10px;
  background-color: rgba(0, 0, 0, .3);
}

.uploadimgvideo .el-upload-list {
  display: none;
}

.out-side-frame {
  .uploadBox {
    cursor: pointer;
    width: 120px;
    height: 120px;
    display: inline-block;
    background-color: rgba(0, 0, 0, .3);
    padding: 10px;
    text-align: center;
    margin-top: 10px;

    i {
      font-size: 28px;
      color: #fbd102;
      cursor: pointer;
    }

    .line-one {
      margin-top: 8px;
      line-height: 20px;
    }

    span {
      font-size: 12px;
      color: rgba(255, 255, 255, 0.7);
    }
  }
}
</style>
